*cd "/Users/sanchariroy/Google Drive/Sanchari_F/DBW/data/prepared_data/"
*cd "/Users/bsog0079/Dropbox/DBW/agencytrainingpaper/ReSTAT_revisions/prepared_data"
cd "/Users/sr432/Google Drive/Sanchari_F/DBW/data/prepared_data_dropbox/"

use baseline_endline_data, clear

set more off

************************************************************************************************
***REGRESSIONS: MULTIPLE HYPOTHESIS TESTING USING ANDERSON CORRECTION FOR PSYCHOLOGICAL OUTCOMES
************************************************************************************************

*multiple hypothesis testing using anderson correction

gen have=1 if  ashamed_bline!=. & sworth_bline!=. & z_resolve_bline!=. & z_comf_bline!=. & happydum_bline!=. & aspir_bline!=. & z_decision_bline!=.
egen have_sum=sum(have)
keep if have==1

****Switch signs so postive is better for all outcomes
gen ashamed2=-ashamed

*** Switch signs on baseline so all are in postiive direction
ge ashamed_bline2=-ashamed_bline

*** Examine Correlations
corr ashamed2 sworth z_resolve z_comf happydum aspir z_decision

**** Create Variance-Covariance Matrix
gen x1=ashamed_bline2
gen x2=sworth_bline
gen x3=z_resolve_bline
gen x4=z_comf_bline
gen x5=happydum_bline
gen x6=aspir_bline
gen x7=z_decision_bline

**** Create Variances and Covariances
forvalues i=1(1)7 {
	forvalues j=1(1)7{
		egen x`i'`j'=sum(x`i'*x`j')
		replace x`i'`j'=x`i'`j'/have_sum
		}
}

*** Put into matrix ****
matrix var_covar=J(7,7,.)

forvalues i=1(1)7 {
	forvalues j=1(1)7{
		matrix var_covar[`i',`j']=x`i'`j'[1]
}
}

**** Invert matrix 
mata: inv_cov=cholinv(st_matrix("var_covar"))
mata: st_matrix("vc2", inv_cov)


*** Display matrix and sum rows to create weights

matrix list vc2
forvalues i=1(1)7{
	gen w`i'=vc2[`i',1] + vc2[`i',2] + vc2[`i',3] + vc2[`i',4] + vc2[`i',5] + vc2[`i',6] + vc2[`i',7]
}

*** Rescale so weights sum to 1
egen wsum=rowtotal(w1 w2 w3 w4 w5 w6 w7)
forvalues i=1(1)7{
	replace w`i'=w`i'/wsum
}

**** Create psych index

gen component1=w1*ashamed2
gen component2=w2*sworth
gen component3=w3*z_resolve
gen component4=w4*z_comf
gen component5=w5*happydum
gen component6=w5*aspir
gen component7=w5*z_decision

forvalues i=1(1)7{
	gen b_component`i'=w`i'*x`i'
}

**** index of first 4 psych variables
gen index1=component1+component2+component3+component4

gen b_index1=b_component1+b_component2+b_component3+b_component4

**** index of next 3 psych variables
gen index2=component5+component6+component7

gen b_index2=b_component5+b_component6+b_component7

**** index of all 7 psych variables
gen index3=component1+component2+component3+component4+component5+component6+component7

gen b_index3=b_component1+b_component2+b_component3+b_component4+b_component5+b_component6+b_component7

*** construct indices
label variable b_index1 "Baseline Index of Proxies of Self-Image"
label variable b_index2 "Baseline Index of Other Psychological Outcomes"
label variable b_index3 "Baseline Index of All Psychological Variables"

label variable z_comf "Comfort in Public"
label variable z_resolve "Ability to face challenges"
label variable z_decision "Decision-making"
label variable happydum "Happiness"
label variable aspir "Aspiration"
label variable sworth "Self-worth"
label variable ashamed "Shame"

label variable post "Post"
label variable treatpost "Treatment*Post"

label var z_resolve_bline "Ability to face challenges at baseline"
label var sworth_bline "Self-worth at baseline"
label var z_comf_bline "Comfort in Public at baseline"
label var ashamed_bline "Shame at baseline"
label var happydum_bline "Happiness at baseline"
label var aspir_bline "Aspiration at baseline"
label var z_decision_bline "Decision-making at baseline"

label variable index1 "Index of Proxies of Self-Image"
label variable index2 "Index of Other Psychological Outcomes"
label variable index3 "Index of All Psychological Variables"

corr index1 ashamed_bline2 sworth_bline z_resolve_bline z_comf_bline happydum_bline aspir_bline z_decision_bline

corr b_index1 ashamed_bline2 sworth_bline z_resolve_bline z_comf_bline happydum_bline aspir_bline z_decision_bline


/**Table 3**/

eststo clear

*Col 5
eststo reg5: reg index1 treat b_index1 areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg5

estadd matrix pvalues = pvalues

*Col 9
eststo reg9: reg index2 treat b_index2 areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg9

estadd matrix pvalues = pvalues

esttab using maintables.rtf, append se title(Table 3: Program Impact on Proxies of Self-Image and Other Psychological Variables, ANCOVA) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat b_index1 b_index2) order(treat b_index1 b_index2) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A2**/

eststo clear

*Col 5
eststo reg5: reg index1 treat b_index1 areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg5

estadd matrix pvalues = pvalues

*Col 9
eststo reg9: reg index2 treat b_index2 areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg9

estadd matrix pvalues = pvalues

esttab using appendtables.rtf, append se title(Appendix Table A2: Program Impact on Proxies of Self-Image and Other Psychological Variables, ANCOVA with Baseline Controls) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat b_index1 b_index2) order(treat b_index1 b_index2) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))

/**Table A3**/

eststo clear

*Col 5
eststo: reg index1 treat areadum1-areadum2 if post==1, cl(hhid)

*Col 9
eststo: reg index2 treat areadum1-areadum2 if post==1, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A3: Program Impact on Proxies of Self-Image and Other Psychological Variables, Endline) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat) order(treat) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A4**/

eststo clear

*Col 5
eststo: reg index1 treat areadum1-areadum2 $controls if post==1, cl(hhid)

*Col 9
eststo: reg index2 treat areadum1-areadum2 $controls if post==1, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A4: Program Impact on Proxies of Self-Image and Other Psychological Variables, Endline with Baseline Controls) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat) order(treat) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A5**/

eststo clear

*Col 5
eststo: reg index1 treat post treatpost areadum1-areadum2, cl(hhid)

*Col 9
eststo: reg index2 treat post treatpost areadum1-areadum2, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A5: Program Impact on Proxies of Self-Image and Other Psychological Variables, Difference-in-differences) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat post treatpost) order(treat post treatpost) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A6**/

eststo clear

*Col 5
eststo: reg index1 treat post treatpost $controls areadum1-areadum2, cl(hhid)

*Col 9
eststo: reg index2 treat post treatpost $controls areadum1-areadum2, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A6: Program Impact on Proxies of Self-Image and Other Psychological Variables, Difference-in-differences with Baseline Controls) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat post treatpost) order(treat post treatpost) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A11**/

eststo clear

eststo: reg index3 treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg index3 treat post treatpost areadum1-areadum2, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A11: Adjusting for Multiple Hypothesis Testing using Anderson (2008) for Composite Summary Psychological Index) cells(b(star fmt(2)) se(par fmt(2))) keep(treat post treatpost) order(treat post treatpost) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


